﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("运行开始");
            WaitTest();
            MessageBox.Show("运行结束");
        }

        private void WaitTest()
        {
            Thread.Sleep(3000);
        }

        private void DoWaitTest()
        {
            Thread.Sleep(5000);
        }

        private async Task WaitTestAsync()
        {
            await Task.Delay(3000);
            MessageBox.Show("方法运行结束");
        }

        private async Task DoWaitTestAsync()
        {
            await Task.Delay(5000);
            MessageBox.Show("方法运行结束");
        }

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("运行开始");
            await DoWaitTestAsync();
            MessageBox.Show("运行结束");
        }

        private async void Button_Click_2(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("运行开始");
            await WaitTestAsync();
            await DoWaitTestAsync();
            MessageBox.Show("运行结束");
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("运行开始");
            WaitTestAsync();
            DoWaitTestAsync();
            MessageBox.Show("运行结束");
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("运行开始");
            Task.Run(() => WaitTestAsync()); 
            Task.Run(() => DoWaitTestAsync()); 
            MessageBox.Show("运行结束");
        }
    }
}